sysroot: Error out on deploy --os=<unknown> which has not been initialized
authorColin Walters <walters@verbum.org>
Wed, 8 Jan 2014 23:29:05 +0000 (18:29 -0500)
committerColin Walters <walters@verbum.org>
Wed, 8 Jan 2014 23:30:38 +0000 (18:30 -0500)
We should hard require "ostree admin os-init foo" before letting
deployments go there; it's too easy to typo the argument.

src/libostree/ostree-sysroot-deploy.c
tests/test-admin-deploy-1.sh

index d908cd87551679d21246907f8ef1ba8b3d1f2bcd..b14b2b715eed2e01b0f0c47a9ba40e5e4acd7946 100644 (file)
@@ -1043,6 +1043,7 @@ ostree_sysroot_deploy_one_tree (OstreeSysroot     *self,
   gs_unref_object OstreeDeployment *new_deployment = NULL;
   gs_unref_object OstreeDeployment *merge_deployment = NULL;
   gs_unref_object OstreeRepo *repo = NULL;
+  gs_unref_object GFile *osdeploydir = NULL;
   gs_unref_object GFile *commit_root = NULL;
   gs_unref_object GFile *tree_kernel_path = NULL;
   gs_unref_object GFile *tree_initramfs_path = NULL;
@@ -1055,6 +1056,14 @@ ostree_sysroot_deploy_one_tree (OstreeSysroot     *self,
   if (osname == NULL)
     osname = ostree_deployment_get_osname (self->booted_deployment);
 
+  osdeploydir = ot_gfile_get_child_build_path (self->path, "ostree", "deploy", osname, NULL);
+  if (!g_file_query_exists (osdeploydir, NULL))
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                   "No OS named \"%s\" known", osname);
+      goto out;
+    }
+
   if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
     goto out;
 
index e591f9bd7fbcbb061cd69775910722eecb3e6422..c1151d169a1b3222b587ee60383502aa7267d8f0 100755 (executable)
@@ -27,7 +27,7 @@ setup_os_repository "archive-z2" "syslinux"
 
 echo "ok setup"
 
-echo "1..8"
+echo "1..9"
 
 ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmaster/x86_64-runtime
 rev=$(ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
@@ -78,6 +78,8 @@ ostree admin --sysroot=sysroot status
 
 echo "ok third deploy (swap)"
 
+ostree admin --sysroot=sysroot os-init otheros
+
 ostree admin --sysroot=sysroot deploy --os=otheros testos/buildmaster/x86_64-runtime
 assert_not_has_dir sysroot/boot/loader.0
 assert_has_dir sysroot/boot/loader.1
@@ -155,3 +157,8 @@ assert_not_has_dir sysroot/ostree/deploy/testos/deploy/${newrev}.0
 ostree admin --sysroot=sysroot status
 
 echo "ok undeploy"
+
+if ostree admin --sysroot=sysroot deploy --os=unknown testos:testos/buildmaster/x86_64-runtime; then
+    assert_not_reached "Unexpected successful deploy of unknown OS"
+fi
+echo "ok deploy with unknown OS"